package org.surthi.app.school.bean;

import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Table;

import org.hibernate.annotations.GenericGenerator;

@Entity
@Table( name="CLASS" )
public class StandardClass implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = -8109300121448370890L;
	
	/**
	 * Represents a primaryKey/Unique number given to this class
	 */
	private Integer classId;
	
	/**
	 * Represents name of the class
	 */
	private String 	name;
	
	/*
	 * 
	 */
	private Set<Section> sections;
	
	@Id
	@GeneratedValue(generator="increment")
	@GenericGenerator(name="increment", strategy="increment")
	@Column(name="CLASS_ID")
	public Integer getClassId() {
		return classId;
	}

	public void setClassId(Integer classId) {
		this.classId = classId;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}
	
	@ManyToMany(targetEntity=Section.class, cascade= {CascadeType.PERSIST, CascadeType.MERGE})
	@JoinTable(name="CLASS_SECTION", joinColumns=@JoinColumn(name="CLASS_ID"), inverseJoinColumns=@JoinColumn(name="SECT_ID"))	
	public Set<Section> getSections() {
		return sections;
	}
	
	public void setSections(Set<Section> sections) {
		this.sections = sections;
	}
	
	public void addSectionToClass(Section section){
		if (this.sections == null ){
			this.sections = new HashSet<Section>();
		}
		this.sections.add(section);
		section.addClassToSection(this);
	}

}
